package com.hgm.flopgame2.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.WindowManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.hgm.flopgame2.adapter.ScoreAdapter
import com.hgm.flopgame2.database.Score
import com.hgm.flopgame2.databinding.ActivityScoreBinding

class ScoreActivity : AppCompatActivity() {

    private val binding: ActivityScoreBinding by lazy {
        ActivityScoreBinding.inflate(layoutInflater)
    }
    private lateinit var name:String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
        setContentView(binding.root)

        initView()

        binding.btnRestart.setOnClickListener {
            //重新游戏
            var intent = Intent(this,MainActivity::class.java)
            intent.putExtra("tag",1)
            intent.putExtra("up_name",name)
            startActivity(intent)
            finish()
        }
    }

    private fun initView() {
        //获取成绩列表、名字
        var scoreList = intent.getSerializableExtra("list") as ArrayList<Score>
        name = intent.getStringExtra("name").toString()

        binding.recyclerView.apply {
            adapter = ScoreAdapter(scoreList,name)//传名字到适配器
            layoutManager =
                LinearLayoutManager(this@ScoreActivity, LinearLayoutManager.VERTICAL, false)
        }
    }
}